<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>表白墙</title>
</head>

<body>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        .container {
            width: 600px;
            margin: 0, auto;
        }

        h1 {
            text-align: center;
            padding: 20px 0;
        }

        p {
            text-align: center;
            font-size: 16px;
            color: #666;
            padding: 10px 0;
        }

        .row {
            display: flex;
            justify-content: center;
            align-items: center;
            height: 40px;
        }

        .row span {
            width: 100px;
        }

        .row .edit {
            width: 200px;
            height: 36px;
        }

        .row .submit {
            width: 300px;
            height: 40px;
            background-color: orange;
            color: white;
            border: none;
        }

        .row .submit:active {
            background-color: aqua;
        }
    </style>

    <div class="container">
        <h1>表白墙</h1>
        <p>输入后点击提交, 将会把消息显示在墙上</p>

        <form action="message" method="post">
            <div class="row">
                <span>谁：</span>
                <input type="text" class="edit" name="from">
            </div>

            <div class="row">
                <span>对谁：</span>
                <input type="text" class="edit" name="to">
            </div>

            <div class="row">
                <span>说什么：</span>
                <input type="text" class="edit" name="message">
            </div>

            <div class="row">
                <input type="submit" value="提交" class="submit">
            </div>
        </form>


        <!-- 这个 div 通过循环的方式，来获取内容 -->
        <!-- 这里面数组的每个元素，期望是一个 message对象 -->
        <div class="row" th:each="message : ${messages}">
            <span th:text="${message.from}"></span>
            对
            <span th:text="${message.to}"></span>
            说:
            <span th:text="${message.message}"></span>
        </div>

    </div>

    <script>

        // 现在用java来动态生成当前页面的内容，不需要前端的标签
        //先点击提交
        // let submitBtn = document.querySelector('.submit');
        // submitBtn.onclick = function () {
        //     // 1、获取输入框里面的内容
        //     let edits = document.querySelectorAll('.edit');
        //     let from = edits[0].value;
        //     let to = edits[1].value;
        //     let message = edits[2].value;
        //     console.log(from + "," + to + "," + message)
        //     if (from == '' || to == '' || message == '') {
        //         return;
        //     }

        //     // 2、根据输入框里面的内容，构造HTML元素，添加到页面上
        //     //    接下来的每个消息，都使用 div.row 来实现表示
        //     let row = document.createElement('div');
        //     row.className = 'row';
        //     row.innerHTML = from + ' 对 ' + to + ' 说 ' + message;

        //     let container = document.querySelector('.container');
        //     container.appendChild(row);

        //     // 3、把上次输入的内容清空
        //     for (let i = 0; i < edits.length; i++) {
        //         edits[i].value = '';
        //     }
        // }

    </script>


</body>

</html>